#!/bin/bash

# 用法说明
usage() {
    echo "用法: $0 <仓库路径> <提交标题>"
    echo "示例: $0 /path/to/repo '修复了登录问题'"
    exit 1
}

# 检查参数数量
if [ "$#" -ne 2 ]; then
    usage
fi

REPO_PATH="$1"
COMMIT_TITLE="$2"

# 检查仓库目录是否存在
if [ ! -d "$REPO_PATH/.git" ]; then
    echo "错误: $REPO_PATH 不是一个有效的 Git 仓库"
    exit 1
fi

# 进入仓库目录
cd "$REPO_PATH" || exit 1

# 搜索包含指定标题的提交
FOUND_COMMIT=$(grep -rn --include=".git-log-oneline-*.cache" "$COMMIT_TITLE" .)

if [ -n "$FOUND_COMMIT" ]; then
    echo "找到匹配的提交:"
    echo "$FOUND_COMMIT"
    exit 0
else
    echo "未找到标题包含 '$COMMIT_TITLE' 的提交"
    exit 1
fi